package com.link.wseller.mapper.impl;

import com.link.wseller.domain.ProductInfo;
import com.link.wseller.mapper.ProductCategoryMapper;
import com.link.wseller.mapper.ProductInfoMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface ProductInfoMapperImpl extends ProductInfoMapper{

    @Select("select * from product_info where product_status = 0 limit #{page},#{size}")
    @Results({
            @Result(column="product_id", property="productId", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR),
            @Result(column="product_price", property="productPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="product_stock", property="productStock", jdbcType=JdbcType.INTEGER),
            @Result(column="product_description", property="productDescription", jdbcType=JdbcType.VARCHAR),
            @Result(column="product_icon", property="productIcon", jdbcType=JdbcType.VARCHAR),
            @Result(column="product_status", property="productStatus", jdbcType=JdbcType.TINYINT),
            @Result(column="category_type", property="categoryType", jdbcType=JdbcType.INTEGER),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<ProductInfo> selectByProductInfoStatus(@Param("page") Integer page, @Param("size") Integer size);

    @Select("select * from product_info where product_status = 0")
    @Results({
            @Result(column="product_id", property="productId", jdbcType= JdbcType.VARCHAR, id=true),
            @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR),
            @Result(column="product_price", property="productPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="product_stock", property="productStock", jdbcType=JdbcType.INTEGER),
            @Result(column="product_description", property="productDescription", jdbcType=JdbcType.VARCHAR),
            @Result(column="product_icon", property="productIcon", jdbcType=JdbcType.VARCHAR),
            @Result(column="product_status", property="productStatus", jdbcType=JdbcType.TINYINT),
            @Result(column="category_type", property="categoryType", jdbcType=JdbcType.INTEGER),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<ProductInfo> selectByProduct();

    @Update("update product_info set product_status = 1 where product_id = #{productId}")
    int updateOnSaleStatus(String productId);

    @Update("update product_info set product_status = 0 where product_id = #{productId}")
    int updateOffSaleStatus(String productId);
}
